package com.miukoo.aikao.admin.controller.v1;

import com.miukoo.aikao.core.dtos.ApiResult;
import com.miukoo.aikao.core.pojos.SecurityUser;
import com.miukoo.aikao.core.utils.ApiUtils;
import com.miukoo.aikao.core.utils.AppUserUtils;
import com.miukoo.aikao.metadata.dto.response.SysUserLoginDto;
import com.miukoo.aikao.metadata.pojos.SysUser;
import com.miukoo.aikao.metadata.service.SysUserRoleService;
import com.miukoo.aikao.metadata.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 管理用户控制器
 * </p>
 *
 * @author 聪明笨狗
 * @since 2020-04-13 16:57
 */
@Api(tags = {"用户信息"})
@RestController
@RequestMapping("/login/user")
public class UserInfoController {

    @Autowired
    SysUserService sysUserService;
    @Autowired
    SysUserRoleService sysUserRoleService;
    
    /**
     * 获取会话
     * @return
     */
    @ApiOperation(value = "获取会话")
    @RequestMapping(value = "/info", method = {RequestMethod.POST})
    public ApiResult<SysUserLoginDto> info(@RequestParam("token") String token) {
        SecurityUser user = AppUserUtils.getUser();
        SysUser suser = sysUserService.getById(user.getId());
        SysUserLoginDto dto = new SysUserLoginDto();
        BeanUtils.copyProperties(suser,dto);
        List<String> roles = sysUserRoleService.listRoles(user.getId());
        dto.setRoles(roles);
        return ApiUtils.success(dto);
    }

}
